(function () {
    var _Components = {};
    var _Models = [];
    var _Pages = [];
    var _ExpandDataActions = {};
    var _ExpandPages = {}
    var _ExpandEventActions = {};

    var a2dmah5 = {
        //扩展页面行为
        useExpandPageAction: function () { return function () { return 1 } },
        //添加组件
        addComponent: function (type, component) {
            _Components[type] = component;
        },
        //获取组件
        getComponent: function (type) {
            return _Components[type];
        },
        addModel: function (model) {
            _Models.push(model);
        },
        getModels: function (dvaIndex) {
            var list = [];

            for (var i = 0; i < _Models.length; i++) {
                list.push(_Models[i](dvaIndex));
            }

            return list;
        },
        addPage: function (page) {
            _Pages.push(page);
        },
        addExpandPage: function (id, expandPage) {
            _ExpandPages[id] = expandPage;
        },
        getPages: function (pageTemplates, get) {
            var list = [];

            for (var i = 0; i < _Pages.length; i++) {
                list.push(_Pages[i](pageTemplates, function (id) { var fn = _ExpandPages[id]; return fn ? fn(get) : null; }));
            }

            return list;
        },
        addExpandDataAction: function (className, actionName, fn) {
            _ExpandDataActions[className] = _ExpandDataActions[className] || {};
            _ExpandDataActions[className][actionName] = fn;
        },
        getExpandDataActions: function (className, get) {
            var obj = {};
            var actions = _ExpandDataActions[className];
            if (actions) {
                for (var key in actions) {
                    obj[key] = actions[key](get);
                }
            }
            return obj;
        },
        addExpandEventAction: function (actionName, fn) {
            _ExpandEventActions[className] = _ExpandEventActions[className] || {};
            _ExpandEventActions[className][actionName] = fn;
        },
        getExpandEventActions: function (className, get) {
            var obj = {};
            var actions = _ExpandEventActions[className];
            if (actions) {
                for (var key in actions) {
                    obj[key] = actions[key](get);
                }
            }
            return obj;
        }
    };

    window.a2dmah5 = a2dmah5;
})(window);